from rest_framework import serializers
from question.models import Label, Question, Reply
from serializers.usersimpleserializers import UserSimpleSeialiser


class LabelSerializerView(serializers.ModelSerializer):
    class Meta:
        model = Label
        fields = '__all__'


# 个人中心使用简易版本的Label序列化器
class QuestionSimpleSerializerView(serializers.ModelSerializer):
    labels = serializers.StringRelatedField(many=True)
    user = serializers.StringRelatedField(read_only=True)

    class Meta:
        model = Question
        fields = '__all__'


# Reply自关联序列化器
class ReplySelfSerializerView(serializers.ModelSerializer):
    user = UserSimpleSeialiser

    class Meta:
        model = Reply
        fields = ['id', 'createtime', 'useful_count', 'unuseful_count', 'user']


# 个人中心使用简易版本的Reply序列化器
class ReplySimpleSerializerView(serializers.ModelSerializer):

    subs = ReplySelfSerializerView(many=True)
    user = UserSimpleSeialiser
    parent = None

    class Meta:
        model = Reply
        fields = '__all__'
